import { reqShopcartList, postCheck, postAllCheck, reqdelShopCart } from'@/api'

const state = {
  cartList:[]
}
const mutations = {
  GETCARTLIST(state,cartList){
    state.cartList = cartList
  }
}
const actions = {
  async getCartList({commit}){
    const res = await reqShopcartList()
    if(res.code == 200){
      commit('GETCARTLIST',res.data)
    }else{
      return Promise.reject();
    }
  },
  async updataCheck({commit},data){
    const res = await postCheck(data)
    if(res.code == 200){
      commit('GETCARTLIST',res.data)
    }
  },
  async updataAllCheck({commit},data){
    const res = await postAllCheck(data)
    if(res.code == 200){
      commit('GETCARTLIST',res.data)
    }
  },
  //删除购物车商品
  async delShopCart({commit}, data){
    const res = await reqdelShopCart(data)
    if(res.code == 200){
      commit('GETCARTLIST',res.data)
    }else{
      return Promise.reject();
    }
  }
}

export default{
  state,
  mutations,
  actions
}